#pragma once

#include "motor_drivers.hpp"

namespace MotorDrivers{


    class CANSocket : public MotorDrivers::HWSocket{
    public:
        explicit CANSocket(const std::string& socketName, uint16_t recvID, uint16_t sendID, uint8_t canDLC);
        ~CANSocket() override;
        bool socket_Init() override;
        bool socket_Send(uint8_t* frame_data) override;
        SocketFrame socket_Read() override;
        int16_t socket_ReadMutation(uint8_t index) override;

        
        
    private:
        std::string socketName_;
        int32_t socket_;
        can_filter rfilter_[1];
        uint16_t recvID_;
        uint16_t sendID_;
        uint8_t canLength_;

        static constexpr int MAX_BUFFER_SIZE = 1024*1024;

        std::mutex mtx;
        std::condition_variable cv;
        std::atomic<bool> pause {false};
        void socket_ReadingThread();
        void socket_PauseThread();
        void socket_ResumeThread();
        std::thread readThread;
        void socket_DetectMutation();

        log logCAN{"logCAN", "./logs/"};
        void CANLog();
        int16_t mutation[16] = {0};
    };

}